﻿CREATE VIEW [Mapping].[vMappingItemView]
  AS  
    SELECT
    [MappingItem].[Id],
    [Priority], [Masked], [Enabled],
    [TargetKey].KeyValue AS TargetKeyValue,
    KeyAlternateValue AS TargetKeyAlternateValue,
    [MappingGroup].Id AS GroupId, GroupName, 
    [SourceSystem].Id AS SourceSystem, SystemName,
    Mapping.GetSourceKeyExpression(MappingItem.Id) SourceKeyExpression
  FROM Mapping.MappingItem
  JOIN Mapping.TargetKey ON TargetKey.Id = MappingItem.TargetKey
  JOIN Mapping.Category ON Category.Id = TargetKey.Category
  JOIN Mapping.MappingGroup ON MappingGroup.Id = MappingItem.[Group]
  JOIN Mapping.SourceSystem ON SourceSystem.Id = MappingGroup.SourceSystem